home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt.image;
-
- import java.awt.image.ImageProducer;
- import java.io.BufferedInputStream;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import sun.awt.image.GifImageDecoder;
- import sun.awt.image.ImageDecoder;
- import sun.awt.image.JPEGImageDecoder;
- import sun.awt.image.URLImageSource;
-
- public class StreamImageSource extends URLImageSource implements ImageProducer {
- InputStream stream;
- int type;
- URL base;
- static URL baseUrl;
- public static final int GIF = 0;
- public static final int JPEG = 1;
-
- public StreamImageSource(InputStream is, int type) {
- this(baseUrl, is, type);
- }
-
- public StreamImageSource(URL base, InputStream is, int type) {
- super(base);
- if ((type & 1) == 0) {
- throw new IllegalArgumentException("Unsupported image type:" + type);
- } else {
- this.stream = is;
- this.type = type;
- }
- }
-
- public static void setBaseUrl(URL base) {
- baseUrl = base;
- }
-
- public static URL getBaseUrl() {
- return baseUrl;
- }
-
- protected ImageDecoder getDecoder() {
- InputStream is = new BufferedInputStream(this.stream);
- switch (this.type) {
- case 0:
- return new GifImageDecoder(this, is);
- case 1:
- return new JPEGImageDecoder(this, is);
- default:
- throw new IllegalArgumentException("Unsupported image type:" + this.type);
- }
- }
-
- static {
- try {
- baseUrl = new URL("file://");
- } catch (MalformedURLException var0) {
- }
- }
- }
-